package net.xdclass.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.xdclass.manager.LinkGroupManager;
import net.xdclass.mapper.LinkGroupMapper;
import net.xdclass.model.LinkGroupDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：zhouyang
 * @date ：Created in 2022/5/9 10:11
 * @modified By：
 * @version: $
 */
@Slf4j
@Service
public class LinkGroupManagerImpl implements LinkGroupManager {
    @Autowired
    private LinkGroupMapper linkGroupMapper;

    @Override
    public int add(LinkGroupDO linkGroupDO) {
        int insert = linkGroupMapper.insert(linkGroupDO);
        return insert;
    }

    @Override
    public int del(Long groupId, Long accountNo) {
        int rows = linkGroupMapper.delete(new QueryWrapper<LinkGroupDO>().eq("id", groupId).eq("account_no", accountNo));
        return rows;
    }

    @Override
    public LinkGroupDO detail(Long groupId, Long accountNo) {
        LinkGroupDO linkGroupDO =linkGroupMapper.selectOne(new QueryWrapper<LinkGroupDO>().eq("id",groupId).eq("account_no",accountNo));
        return linkGroupDO;
    }

    @Override
    public List<LinkGroupDO> listAllGroup(Long accountNo) {

        return linkGroupMapper.selectList(new QueryWrapper<LinkGroupDO>().eq("account_no",accountNo));
    }

    @Override
    public int updateById(LinkGroupDO linkGroupDO) {
         int rows = linkGroupMapper.update(linkGroupDO, new QueryWrapper<LinkGroupDO>().eq("id", linkGroupDO.getId()).eq("account_no", linkGroupDO.getAccountNo()));
        return rows;
    }


}
